<!--
 * @Author: [kangjie]
 * @Date: 2022-04-07 14:42:44
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-07 15:04:13
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./js/vue-2.6.12.js"></script>
  <script src="./js/vuex-3.5.1.js"></script>
</head>

<body>
  <div id="app">
    {{aMsg}}--{{bMsg}}--{{msg}}--{{Msg}}
  </div>
  <script>
    let {mapState} = Vuex;
    // 声明多个状态机 多个仓库
    let aModule = {
      // 命名空间
      namespaced:true,
      state: {
        aMsg: 'a仓库公共的属性',
        msg:'a的仓库里面的msg'
      },
      getters: {},
      mutations: {},
      actions: {}
    };
    let bModule = {
      namespaced:true,
      state: {
        bMsg: 'b仓库公共的属性'
      },
      getters: {},
      mutations: {},
      actions: {}
    };
    // 创建状态机对象
    let store = new Vuex.Store({
      // 模块化导入
      modules: {
        // 重命名名字是属性名
        a:aModule,
        b:bModule
      },
      // state: {},
      // getters: {},
      // mutations: {},
      // actions: {}
    });
    // 注册状态机
    new Vue({
      el: "#app",
      store,
      data: {
        msg:'我是vue实例数据模型中的数据'
      },
      computed:{
        // ...mapState('aModule',['aMsg']),
        // ...mapState('bModule',['bMsg']),
        // ...mapState('a',['aMsg','msg']),
        ...mapState('a',{
          // 第二个参数对象给仓库中的数据重命名 对象内的属性名是新名字
          aMsg:'aMsg',
          Msg:'msg'
        }),
        ...mapState('b',['bMsg']),
      },
      methods: {

      }
    })
  </script>
</body>

</html>